package com.threadPool;

import com.threadPool.enums.RejectedPolicy;
import com.threadPool.pool.MyThreadPool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;

public class Main {
    static Logger logger = LoggerFactory.getLogger(Main.class);
    public static void main(String[] args) throws InterruptedException {
        MyThreadPool myThreadPool = new MyThreadPool(3, TimeUnit.SECONDS, 5, 10, 100, RejectedPolicy.ABORT);
        for (int i = 0; i < 1000; i++) {
            try {
                myThreadPool.execute(() -> {
                    logger.info(Thread.currentThread().getName());
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        logger.error(Thread.currentThread().getName() + " 线程中断");
                    }
                });
            } catch (RejectedExecutionException e) {
                logger.error("任务被拒绝：" + e.getMessage());
            }
        }
//        myThreadPool.setCorePoolSize(1);
//        logger.info("任务运行");
        Thread.sleep(3000);
        myThreadPool.shutdown();
    }
}
